﻿using Microsoft.AspNetCore.Mvc.RazorPages;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XinLife.Application.Interface;
using XinLife.Core.Extention;
using XinLife.Core.Model;
using XinLife.Model;
using XinLife.Model.Model;

namespace XinLife.Application.Implement
{
    public class LoginInfoService : BaseService, ILoginInfoService
    {
        public LoginInfoService(IBaseRepository baseRepository) : base(baseRepository)
        {
        }

        public async Task<object> GetLoginInfoPageList(Pagination page, string queryJson)
        {
            var queryParam = queryJson.ToJObject();
            string? cName = queryParam.Value<string>("name");

            RefAsync<int> totalCount = 0;
            var users = await _db.Queryable<LoginInfo>()
            .WhereIF(!cName.IsEmpty(), a => a.cUser.Contains(cName))
                                .OrderByDescending(t=>t.cCreatedDate)
                                .ToPageListAsync(page.pageIndex, page.pageSize, totalCount);

            return new PageData<LoginInfo>()
            {
                count = totalCount,
                entitys = users
            };
        }
    }
}
